package config

import (
	"fmt"
	viper "github.com/spf13/viper"
)

type MinioConfig struct {
	Endpoint  string `json:"endpoint"`
	AccessKey string `json:"access_key"`
	SecretKey string `json:"secret_key"`
	Bucket    string `json:"bucket"`
}

var (
	Config *MinioConfig
)

func LoadConfig(path string) {
	viper.SetConfigFile(path)
	err := viper.ReadInConfig()
	if err != nil {
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}

	Config = &MinioConfig{
		Endpoint:  viper.GetString("minio_endpoint"),
		AccessKey: viper.GetString("minio_access_key"),
		SecretKey: viper.GetString("minio_secret_key"),
		Bucket:    viper.GetString("minio_bucket"),
	}
	fmt.Printf("Minio Config: %+v\n", *Config)

	if Config.Endpoint == "" || Config.AccessKey == "" || Config.SecretKey == "" || Config.Bucket == "" {
		panic("Minio config is not valid")
	}

}
